package com.night.student.rabbitmq;

import com.night.common.entity.student.SelectCourseVo;
import com.night.student.service.LessonService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

/**
 * @author Mr.Wang
 * @ClassName: CourseConsumer
 * @Description: //TODO
 * @date: 2022/10/22-21:09
 */
@Component
public class CourseConsumer {
    @Autowired
    LessonService lessonService;

    @Autowired
    RedisTemplate redisTemplate;

    @RabbitListener(queues = "queueCourse")
    @Transactional(rollbackFor = Exception.class)
    public void receiveCourse(SelectCourseVo selectCourseVo, Message message, Channel channel) throws IOException {
        //执行选课成功后操作
        lessonService.executeAfterSelectLesson(selectCourseVo);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
